package com.ruoyi.customer.service.impl;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.customer.domain.BusCustomerComplaints;
import com.ruoyi.customer.domain.Customer;
import com.ruoyi.customer.mapper.BusCustomerComplaintsMapper;
import com.ruoyi.customer.mapper.CustomerMapper;
import com.ruoyi.customer.service.IBusCustomerComplaintsService;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * 客户投诉Service业务层处理
 *
 * @author xiaochen
 * @date 2022-11-30
 */
@Service
public class BusCustomerComplaintsServiceImpl extends ServiceImpl<BusCustomerComplaintsMapper, BusCustomerComplaints> implements IBusCustomerComplaintsService {


    @Resource
    private BusCustomerComplaintsMapper busCustomerComplaints;
    @Resource
    private SysUserMapper userMapper;
    @Resource
    private CustomerMapper customerMapper;
    /**
     * 查询客户投诉列表
     *
     * @param busCustomerComplaints 客户投诉
     * @return 客户投诉
     */
    @Override
    public List<BusCustomerComplaints> selectBusCustomerComplaintsList(BusCustomerComplaints busCustomerComplaints) {
        return getBaseMapper().selectBusCustomerComplaintsList(busCustomerComplaints);
    }

    @Override
    public boolean save(BusCustomerComplaints entity) {
        Long complainantId = entity.getComplainantId();
        Customer customer = customerMapper.getById(complainantId);
        entity.setPhone(customer.getPhone());
        entity.setComplainantName(customer.getName());
        Long respondentId = entity.getRespondentId();
        SysUser sysUser = userMapper.selectUserById(respondentId);
        entity.setRespondentName(sysUser.getUserName());
        entity.setStatus(0);
        entity.setCreatedTime(new Date());
        entity.setCreatorId(SecurityUtils.getUserId());
        getBaseMapper().insert(entity);
        return true;
    }

    @Override
    public BusCustomerComplaints getById(Serializable id) {
        return busCustomerComplaints.getById(id);
    }
}
